package com.phone.modules.rms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.phone.common.api.CommonPage;
import com.phone.common.api.CommonResult;
import com.phone.modules.rms.dto.RmsQueryDTO;
import com.phone.modules.rms.model.RmsGame;
import com.phone.modules.rms.service.RmsGameService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 游戏帧率排行表 前端控制器
 * </p>
 *
 * @author WangHao
 * @since 2022-04-18
 */
@RestController
@RequestMapping("/game")
public class RmsGameController {

    @Autowired
    RmsGameService gameService;

    @ApiOperation("前台展示-检索游戏帧率")
    @RequestMapping(value = "/searchList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult searchList(RmsQueryDTO queryDTO) {
        Page page = gameService.searchList(queryDTO);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation(value = "分页获取游戏帧率信息列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getList(@RequestParam(value = "keyword", required = false) String keyword,
                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page page = gameService.listGame(keyword, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation(value = "添加游戏帧率信息")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody RmsGame game) {
        boolean result = gameService.saveGame(game);
        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation(value = "根据编号查询游戏帧率信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getItem(@PathVariable("id") Long id) {
        return CommonResult.success(gameService.getById(id));
    }


    @ApiOperation(value = "更新游戏帧率信息")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable("id") Long id,
                               @RequestBody RmsGame game) {
        boolean result = gameService.updateGame(id, game);
        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation(value = "批量删除游戏帧率信息")
    @RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult deleteBatch(@RequestParam("ids") List<Long> ids) {
        boolean result = gameService.deleteGame(ids);
        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

}

